
#include <basic_types.h>

#include <hld/hld_dev.h>
#include <hld/dmx/dmx_dev.h>
#include <hld/dmx/dmx.h>

#include <api/libc/alloc.h>
#include <api/libc/printf.h>
#include <api/libc/string.h>
#include <api/libtsi/si_types.h>
//#include <api/libtsi/si_table.h>

#include <api/libsubt/lib_subt.h>
#include <api/libsubt/subt_osd.h>
#include <hld/sdec/sdec.h>
#include <hld/osd/osddrv.h>

extern struct subt_config_par g_subt_config_par;//
extern BOOL g_subt_init;

extern void osd_subt_enter_no_bl();
extern void osd_subt_leave_no_bl();
extern void osd_subt_set_clut_no_bl(UINT8 entry_id,UINT8 y,UINT8 cb,UINT8 cr,UINT8 t);
extern void osd_subt_update_clut_no_bl();

extern void osd_subt_clear_page_no_bl();
extern INT32 osd_subt_create_region_no_bl(UINT8 region_idx,struct OSDRect *rect);
extern INT32 osd_subt_delete_region_no_bl(UINT8 region_idx);
extern INT32 osd_subt_region_show_no_bl(UINT8 region_idx,UINT8 on);
extern INT32 osd_subt_draw_pixel_no_bl(UINT8 region_idx,UINT16 x,UINT16 y,UINT8 data);
extern BOOL osd_region_is_created_no_bl(UINT8 region_idx);
//extern void osd_subt_draw_pixelmap_no_bl(struct OSDRect rect, UINT8* data);
extern INT32 osd_subt_get_region_addr_no_bl(UINT8 region_idx,UINT16 y, UINT32 *addr);
extern INT32 osd_subt_display_define_no_bl(struct sdec_display_config *cfg);

extern void osd_subt_enter_2m();
extern void osd_subt_leave_2m();
extern void osd_subt_set_clut_2m(UINT8 entry_id,UINT8 y,UINT8 cb,UINT8 cr,UINT8 t);
extern void osd_subt_clear_page_2m();
extern INT32 osd_subt_create_region_2m(UINT8 region_idx,struct OSDRect *rect);
extern INT32 osd_subt_delete_region_2m(UINT8 region_idx);
extern INT32 osd_subt_region_show_2m(UINT8 region_idx,UINT8 on);
extern INT32 osd_subt_draw_pixel_2m(UINT8 region_idx,UINT16 x,UINT16 y,UINT8 data);
extern BOOL osd_region_is_created_2m(UINT8 region_idx);
//extern void osd_subt_draw_pixelmap_2m(struct OSDRect rect, UINT8* data);
extern INT32 osd_subt_get_region_addr_2m(UINT8 region_idx,UINT16 y, UINT32 *addr);
extern INT32 osd_subt_display_define_2m(struct sdec_display_config *cfg);

void lib_subt_init()
{
//    libc_printf("lib_subt_init\n");
    g_subt_config_par.sys_sdram_size = SYS_SDRAM_SIZE;

#ifdef CC_BY_VBI
    g_subt_config_par.cc_by_vbi = TRUE;
#else
    g_subt_config_par.cc_by_vbi = FALSE;
#endif

#ifdef CC_BY_OSD
    g_subt_config_par.cc_by_osd = TRUE;
#else
    g_subt_config_par.cc_by_osd = FALSE;
#endif

#ifdef OSD_BLOCKLINK_SUPPORT
    g_subt_config_par.osd_blocklink_enable = TRUE;
	g_subt_config_par.g_ps_buf_addr = 0;
	g_subt_config_par.g_ps_buf_len = 0;
#else
    g_subt_config_par.osd_blocklink_enable = FALSE;
	g_subt_config_par.g_ps_buf_addr = (UINT8*)__MM_SUB_PB_START_ADDR;
	g_subt_config_par.g_ps_buf_len = __MM_SUB_PB_LEN;
#endif

#if (SYS_SDRAM_SIZE == 2)
    g_subt_config_par.max_subt_height = __MM_SUB_OSD_LEN/720;
#else
    g_subt_config_par.max_subt_height = 576;
#endif


#ifdef SPEED_UP_SUBT
    g_subt_config_par.speed_up_subt_enable = TRUE;
#else
    g_subt_config_par.speed_up_subt_enable = FALSE;
#endif

#if (SYS_PROJECT_FE == PROJECT_FE_DVBT)
	g_subt_config_par.osd_layer_id = 0;
#else
	g_subt_config_par.osd_layer_id = 1;
#endif

#ifdef HD_SUBTITLE_SUPPORT
    g_subt_config_par.hd_subtitle_support = TRUE;
    g_subt_config_par.subt_width = 1840;
    g_subt_config_par.subt_height = 1024;
    g_subt_config_par.subt_hor_offset = (1920-g_subt_config_par.subt_width)/2;
    g_subt_config_par.subt_ver_offset = (1080-g_subt_config_par.subt_height)/2;
#else
    g_subt_config_par.hd_subtitle_support = FALSE;
    g_subt_config_par.subt_width = SUBT_WIDTH;
    g_subt_config_par.subt_height = SUBT_HEIGHT;
    g_subt_config_par.subt_hor_offset = SUBT_HOR_OFFSET;
    g_subt_config_par.subt_ver_offset = SUBT_VER_OFFSET;
#endif

#ifndef OSD_BLOCKLINK_SUPPORT
    g_subt_config_par.osd_subt_enter = osd_subt_enter_no_bl;
    g_subt_config_par.osd_subt_leave = osd_subt_leave_no_bl;
    g_subt_config_par.osd_subt_set_clut = osd_subt_set_clut_no_bl;
    g_subt_config_par.osd_subt_clear_page = osd_subt_clear_page_no_bl;
    g_subt_config_par.osd_subt_create_region = osd_subt_create_region_no_bl;
    g_subt_config_par.osd_subt_delete_region = osd_subt_delete_region_no_bl;
    g_subt_config_par.osd_subt_draw_pixel = osd_subt_draw_pixel_no_bl;
    g_subt_config_par.osd_region_is_created = osd_region_is_created_no_bl;
 //   g_subt_config_par.osd_subt_draw_pixelmap = osd_subt_draw_pixelmap_no_bl;
    g_subt_config_par.osd_subt_region_show = osd_subt_region_show_no_bl;
    g_subt_config_par.osd_subt_get_region_addr = osd_subt_get_region_addr_no_bl;
    g_subt_config_par.osd_subt_update_clut = osd_subt_update_clut_no_bl;
	g_subt_config_par.osd_subt_display_define = osd_subt_display_define_no_bl;

#else
    g_subt_config_par.osd_subt_enter = osd_subt_enter_2m;
    g_subt_config_par.osd_subt_leave = osd_subt_leave_2m;
    g_subt_config_par.osd_subt_set_clut = osd_subt_set_clut_2m;
    g_subt_config_par.osd_subt_clear_page = osd_subt_clear_page_2m;
    g_subt_config_par.osd_subt_create_region = osd_subt_create_region_2m;
    g_subt_config_par.osd_subt_delete_region = osd_subt_delete_region_2m;
    g_subt_config_par.osd_subt_draw_pixel = osd_subt_draw_pixel_2m;
    g_subt_config_par.osd_region_is_created = osd_region_is_created_2m;
//    g_subt_config_par.osd_subt_draw_pixelmap = osd_subt_draw_pixelmap_2m;
    g_subt_config_par.osd_subt_region_show = osd_subt_region_show_2m;
    g_subt_config_par.osd_subt_get_region_addr = osd_subt_get_region_addr_2m;
	g_subt_config_par.osd_subt_display_define = osd_subt_display_define_2m;
#endif
    g_subt_config_par.osd_get_scale_para = NULL;
    g_subt_init = TRUE;
	LIBSUBT_PRINTF("%s : block_link[%d], OSD[%d], HD[%d]!\n",__FUNCTION__,g_subt_config_par.osd_blocklink_enable,g_subt_config_par.osd_layer_id,
		g_subt_config_par.hd_subtitle_support);
}

